########
# What does this do?
#######
rm(list=ls())

# load libraries
library(tidyverse)

# read data
load('replication/output/coopDV.RData')

# regressions
FinalData$Bahrain = 0
FinalData$Bahrain[FinalData$TargetCountry=="Bahrain" | FinalData$SourceCountry=="Bahrain"] = 1
FinalData$Egypt = 0
FinalData$Egypt[FinalData$TargetCountry=="Egypt" | FinalData$SourceCountry=="Egypt"] = 1
FinalData$Iraq = 0
FinalData$Iraq[FinalData$TargetCountry=="Iraq" | FinalData$SourceCountry=="Iraq"] = 1
FinalData$Israel = 0
FinalData$Israel[FinalData$TargetCountry=="Israel" | FinalData$SourceCountry=="Israel"] = 1
FinalData$Jordan = 0
FinalData$Jordan[FinalData$TargetCountry=="Jordan" | FinalData$SourceCountry=="Jordan"] = 1
FinalData$Kuwait = 0
FinalData$Kuwait[FinalData$TargetCountry=="Kuwait" | FinalData$SourceCountry=="Kuwait"] = 1
FinalData$Lebanon = 0
FinalData$Lebanon[FinalData$TargetCountry=="Lebanon" | FinalData$SourceCountry=="Lebanon"] = 1
FinalData$Oman = 0
FinalData$Oman[FinalData$TargetCountry=="Oman" | FinalData$SourceCountry=="Oman"] = 1
FinalData$Qatar = 0
FinalData$Qatar[FinalData$TargetCountry=="Qatar" | FinalData$SourceCountry=="Qatar"] = 1
FinalData$SA = 0
FinalData$SA[FinalData$TargetCountry=="Saudi Arabia" | FinalData$SourceCountry=="Saudi Arabia"] = 1
FinalData$Syria = 0
FinalData$Syria[FinalData$TargetCountry=="Syria" | FinalData$SourceCountry=="Syria"] = 1
FinalData$Turkey = 0
FinalData$Turkey[FinalData$TargetCountry=="Turkey" | FinalData$SourceCountry=="Turkey"] = 1
FinalData$UAE = 0
FinalData$UAE[FinalData$TargetCountry=="United Arab Emirates" | FinalData$SourceCountry=="United Arab Emirates"] = 1
FinalData$Yemen = 0
FinalData$Yemen[FinalData$TargetCountry=="Yemen" | FinalData$SourceCountry=="Yemen"] = 1
FinalData$Iran = 0
FinalData$Iran[FinalData$TargetCountry=="Iran" | FinalData$SourceCountry=="Iran"] = 1

modAll = lm(ChangeCoop ~ -1 + Bahrain + Egypt + Iran + Iraq + Israel + Jordan +
              Kuwait + Lebanon + Oman + Qatar + SA + Syria + Turkey + 
              UAE + Yemen, data=FinalData)
summary(modAll) # general changes, no intercept

# table
stargazer::stargazer(modAll, 
                     title = 'Regressing country indicators against changes in dyadic state cooperation.', label = 'reg', 
                     style = 'io', 
                     out = 'replication/paper/figures/regression.tex',
                     dep.var.labels = 'Change in Latent Space Distance', 
                     keep.stat = 'n')
